package main

import (
	"errors"
	"fmt"
)

type calcFunc func(int, int) int

func add(x, y int) int {
	return x + y
}

func sub(x, y int) int {
	return x - y
}

type resFunc func(int, int) (int, error)

func genCalculator(f calcFunc) resFunc {
	return func(x, y int) (int, error) {
		if f == nil {
			return 0, errors.New("invalid calcFunc")
		}
		return f(x, y), nil
	}
}

func main() {
	f := genCalculator(sub)
	res, _ := f(10, 6)
	fmt.Println("Result:", res)
}